package yz.cp.back.admin.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import yz.cp.back.common.utils.PageKit;
import yz.cp.back.s.entity.SysDictData;
import yz.cp.back.s.service.ISysDictDataService;

@Service
public class DictManage {

    @Autowired
    private ISysDictDataService dictDataService;

    public IPage<SysDictData> findByCondition(SysDictData dictData, Pageable pageable) {
        QueryWrapper<SysDictData> wrapper=new QueryWrapper<>();
        IPage<SysDictData> page= PageKit.buildPage(pageable,wrapper);
        //模糊搜素
        if(StrUtil.isNotBlank(dictData.getTitle())){
            wrapper.like("title",dictData.getTitle());
        }

        //状态
        if(dictData.getStatus()!=null){
            wrapper.eq("status",dictData.getStatus());
        }

        //所属字典
        if(StrUtil.isNotBlank(dictData.getDictId())){
            wrapper.eq("dict_id",dictData.getDictId());
        }

        return dictDataService.page(page,wrapper);
    }
}
